﻿/*-------------------------------------
//
//Copyright (C) 2007 开发二组 版权所有。
//
//文件名：CartService.cs
//
//文件功能描述：购物车管理的外观
// 
//创建标识：2007.11.16 殷悦
//创建描述：
// 
//修改标识：2007.11.18 殷悦
//修改描述：根据业务逻辑层修改部分方法
//------------------------------------*/
using System;
using System.Web;
using System.Collections;
using System.Web.Services;
using System.Web.Services.Protocols;
using JXMSTC.SmartBusiness.BFL.BLLFactory;
using JXMSTC.SmartBusiness.BFL.IBLL;

/// <summary>
/// CartService 的摘要说明
/// </summary>
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
public class CartService : System.Web.Services.WebService
{
    private readonly ICart bll = BLLAccess.CreateCart();
    public CartService()
    {

        //如果使用设计的组件，请取消注释以下行 
        //InitializeComponent(); 
    }

    /// <summary>
    /// 判断注册顾客购物车中是否已存在某商品
    /// </summary>
    /// <param name="CustomerID">顾客ID</param>
    /// <param name="ProductID">商品ID</param>
    /// <returns>已存在该商品返回true,不存在返回false</returns>
    [WebMethod(Description = "判断注册顾客购物车中是否已存在某商品")]
    public bool Exists(string CustomerID, string ProductID)
    {
        return bll.Exists(CustomerID, ProductID);
    }

    /// <summary>
    /// 添加商品到购物车
    /// </summary>
    /// <param name="customerID">顾客ID</param>
    /// <param name="productID">商品ID</param>
    /// <returns>添加成功返回true,失败返回false</returns>
    [WebMethod(Description = "添加商品到购物车")]
    public bool Add(string customerID, string productID)
    {
        return bll.Add(customerID, productID);
    }

    /// <summary>
    /// 添加一条商品到购物车，同时设置商品数量
    /// </summary>
    /// <param name="model">购物车的实体</param>
    /// <returns>添加成功返回true,失败返回false</returns>
    [WebMethod(Description = "添加一条商品到购物车，同时设置商品数量")]
    public bool TransferToDB(JXMSTC.SmartBusiness.Common.Model.Cart model)
    {
        return bll.TransferToDB(model);
    }

    /// <summary>
    /// 取得某注册顾客购物车中所有的商品列表
    /// </summary>
    /// <param name="customerID">顾客ID</param>
    /// <returns>商品列表（列表包含ProductID,ProductName,SalesPrice,Quantity,Unit五个字段）</returns>
    [WebMethod(Description = "取得某注册顾客购物车中所有的商品列表")]
    public System.Data.DataSet GetProductList(string customerID)
    {
        return bll.GetProductList(customerID);
    }

    /// <summary>
    /// 更新购物车中商品数量
    /// </summary>
    /// <param name="customerID">顾客ID</param>
    /// <param name="productID">商品ID</param>
    /// <param name="quantity">更新商品数量的目标值</param>
    /// <returns>更新成功返回true,更新失败返回false</returns>
    [WebMethod(Description = "更新购物车中商品数量")]
    public bool UpdateProductQuantity(string customerID, string productID, int quantity)
    {
        return bll.UpdateProductQuantity(customerID, productID, quantity);
    }

    /// <summary>
    /// 删除注册顾客购物车中的某商品
    /// </summary>
    /// <param name="customerID">顾客ID</param>
    /// <param name="productID">商品ID</param>
    /// <returns>删除成功返回true，删除失败返回false</returns>
    [WebMethod(Description = "删除注册顾客购物车中的某商品")]
    public bool DeleteProduct(string customerID, string productID)
    {
        return bll.DeleteProduct(customerID, productID);
    }

    /// <summary>
    /// 清空注册顾客的购物车
    /// </summary>
    /// <param name="customerID">顾客ID</param>
    /// <returns>清空购物车成功返回true,失败返回false</returns>
    [WebMethod(Description = "清空注册顾客的购物车")]
    public bool DeleteAllProduct(string customerID)
    {
        return bll.DeleteAllProduct(customerID);
    }
}

